﻿namespace HRM.CORE.Process
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Grid;
    using APP.HELPER;
    using HRM.CORE;
    
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;
    using APP.HELPER.Utils.Language;
    using Security.ERP;

    public class xucRewardAdd : Common.xucBaseAddH
    {
        private TextEdit cboDecideNumber;
        private TextEdit cboPerson;
        private GridColumn colEmployeeCode;
        private GridColumn colFirstName;
        private GridColumn colLastName;
        private IContainer components = null;
        private DateEdit dtDate;
        private GridLookUpEdit glkEmployeeCode;
        private GridView gridLookUpEdit1View;
        private GroupControl grInformation;
        private LabelControl labelControl1;
        private LabelControl lcDate;
        private LabelControl lcDecideNumber;
        private LabelControl lcForm;
        private LabelControl lcFoundation;
        private LabelControl lcPerson;
        private LabelControl lcReason;
        private string m_EmployeeCode = "";
        private Guid m_RewardID = Guid.Empty;
        private TextEdit txtEmployeeName;
        private MemoEdit txtForm;
        private MemoEdit txtFoundation;
        private MemoEdit txtReason;

        public event SuccessEventHander Success;

        public xucRewardAdd()
        {
            this.InitializeComponent();
            this.InitComponent();
            this.InitData();
        }

        protected override void Add()
        {
            base.Add();
            HRM_PROCESS_REWARD hrm_process_reward = new HRM_PROCESS_REWARD();
            this.txtFoundation.Focus();
        }

        public void Clear()
        {
            this.txtFoundation.Text = "";
            this.txtReason.Text = "";
            this.txtForm.Text = "";
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void glkEmployeeCode_EditValueChanged(object sender, EventArgs e)
        {
            this.m_EmployeeCode = this.glkEmployeeCode.EditValue.ToString();
            this.LoadEmployeeInformation();
        }

        protected override void Init()
        {
        }

        private void InitComponent()
        {
            this.dtDate.DateTime = DateTime.Now;
        }

        private void InitData()
        {
            new HRM_EMPLOYEE().AddGridLookupEdit(this.glkEmployeeCode);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucRewardAdd));
            this.grInformation = new GroupControl();
            this.labelControl1 = new LabelControl();
            this.txtEmployeeName = new TextEdit();
            this.glkEmployeeCode = new GridLookUpEdit();
            this.gridLookUpEdit1View = new GridView();
            this.colEmployeeCode = new GridColumn();
            this.colFirstName = new GridColumn();
            this.colLastName = new GridColumn();
            this.lcForm = new LabelControl();
            this.lcFoundation = new LabelControl();
            this.lcReason = new LabelControl();
            this.dtDate = new DateEdit();
            this.lcDecideNumber = new LabelControl();
            this.lcDate = new LabelControl();
            this.lcPerson = new LabelControl();
            this.cboDecideNumber = new TextEdit();
            this.cboPerson = new TextEdit();
            this.txtFoundation = new MemoEdit();
            this.txtReason = new MemoEdit();
            this.txtForm = new MemoEdit();
            ((ISupportInitialize) base.Err).BeginInit();
            base.imageCollection2.BeginInit();
            this.grInformation.BeginInit();
            this.grInformation.SuspendLayout();
            this.txtEmployeeName.Properties.BeginInit();
            this.glkEmployeeCode.Properties.BeginInit();
            this.gridLookUpEdit1View.BeginInit();
            this.dtDate.Properties.VistaTimeProperties.BeginInit();
            this.dtDate.Properties.BeginInit();
            this.cboDecideNumber.Properties.BeginInit();
            this.cboPerson.Properties.BeginInit();
            this.txtFoundation.Properties.BeginInit();
            this.txtReason.Properties.BeginInit();
            this.txtForm.Properties.BeginInit();
            base.SuspendLayout();
            base.btnSave.Location = new Point(130, 0x112);
            base.btnSave.TabIndex = 1;
            base.btnCancel.Location = new Point(330, 0x112);
            base.btnCancel.TabIndex = 3;
            base.btnSaveNew.Location = new Point(0xe5, 0x112);
            base.btnSaveNew.TabIndex = 2;
            base.imageCollection2.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection2.ImageStream");
            this.grInformation.Controls.Add(this.labelControl1);
            this.grInformation.Controls.Add(this.txtEmployeeName);
            this.grInformation.Controls.Add(this.glkEmployeeCode);
            this.grInformation.Controls.Add(this.lcForm);
            this.grInformation.Controls.Add(this.lcFoundation);
            this.grInformation.Controls.Add(this.lcReason);
            this.grInformation.Controls.Add(this.dtDate);
            this.grInformation.Controls.Add(this.lcDecideNumber);
            this.grInformation.Controls.Add(this.lcDate);
            this.grInformation.Controls.Add(this.lcPerson);
            this.grInformation.Controls.Add(this.cboDecideNumber);
            this.grInformation.Controls.Add(this.cboPerson);
            this.grInformation.Controls.Add(this.txtFoundation);
            this.grInformation.Controls.Add(this.txtReason);
            this.grInformation.Controls.Add(this.txtForm);
            this.grInformation.Dock = DockStyle.Top;
            this.grInformation.Location = new Point(0, 0);
            this.grInformation.Name = "grInformation";
            this.grInformation.Size = new Size(0x1b9, 0x10a);
            this.grInformation.TabIndex = 0;
            this.grInformation.Text = "Th\x00f4ng Tin Khen Thưởng";
            this.labelControl1.AllowHtmlString = true;
            this.labelControl1.Location = new Point(10, 0x24);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(0x60, 14);
            this.labelControl1.TabIndex = 0;
            this.labelControl1.Text = "Chọn nh\x00e2n vi\x00ean <color=red>(*)</color>:";
            this.txtEmployeeName.Enabled = false;
            this.txtEmployeeName.Location = new Point(0xfb, 0x21);
            this.txtEmployeeName.Name = "txtEmployeeName";
            this.txtEmployeeName.Size = new Size(0xaf, 20);
            this.txtEmployeeName.TabIndex = 2;
            this.glkEmployeeCode.Location = new Point(0x87, 0x21);
            this.glkEmployeeCode.Name = "glkEmployeeCode";
            this.glkEmployeeCode.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.glkEmployeeCode.Properties.NullText = "[Chọn nh\x00e2n vi\x00ean]";
            this.glkEmployeeCode.Properties.View = this.gridLookUpEdit1View;
            this.glkEmployeeCode.Size = new Size(110, 20);
            this.glkEmployeeCode.TabIndex = 1;
            this.glkEmployeeCode.EditValueChanged += new EventHandler(this.glkEmployeeCode_EditValueChanged);
            this.gridLookUpEdit1View.Columns.AddRange(new GridColumn[] { this.colEmployeeCode, this.colFirstName, this.colLastName });
            this.gridLookUpEdit1View.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            this.gridLookUpEdit1View.Name = "gridLookUpEdit1View";
            this.gridLookUpEdit1View.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.gridLookUpEdit1View.OptionsView.ShowAutoFilterRow = true;
            this.gridLookUpEdit1View.OptionsView.ShowGroupPanel = false;
            this.colEmployeeCode.Caption = "M\x00e3 nh\x00e2n vi\x00ean";
            this.colEmployeeCode.FieldName = "EmployeeCode";
            this.colEmployeeCode.Name = "colEmployeeCode";
            this.colEmployeeCode.Visible = true;
            this.colEmployeeCode.VisibleIndex = 0;
            this.colFirstName.Caption = "Họ l\x00f3t";
            this.colFirstName.FieldName = "FirstName";
            this.colFirstName.Name = "colFirstName";
            this.colFirstName.Visible = true;
            this.colFirstName.VisibleIndex = 1;
            this.colLastName.Caption = "T\x00ean";
            this.colLastName.FieldName = "LastName";
            this.colLastName.Name = "colLastName";
            this.colLastName.Visible = true;
            this.colLastName.VisibleIndex = 2;
            this.lcForm.Location = new Point(10, 0xa6);
            this.lcForm.Name = "lcForm";
            this.lcForm.Size = new Size(0x72, 13);
            this.lcForm.TabIndex = 7;
            this.lcForm.Text = "H\x00ecnh thức khen thưởng:";
            this.lcFoundation.Location = new Point(10, 0x41);
            this.lcFoundation.Name = "lcFoundation";
            this.lcFoundation.Size = new Size(0x66, 13);
            this.lcFoundation.TabIndex = 3;
            this.lcFoundation.Text = "Căn cứ khen thưởng:";
            this.lcReason.Location = new Point(10, 0x77);
            this.lcReason.Name = "lcReason";
            this.lcReason.Size = new Size(0x5e, 13);
            this.lcReason.TabIndex = 5;
            this.lcReason.Text = "L\x00fd do khen thưởng:";
            this.dtDate.EditValue = null;
            this.dtDate.Location = new Point(0x146, 0xd0);
            this.dtDate.Name = "dtDate";
            this.dtDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtDate.Size = new Size(100, 20);
            this.dtDate.TabIndex = 12;
            this.lcDecideNumber.Location = new Point(10, 210);
            this.lcDecideNumber.Name = "lcDecideNumber";
            this.lcDecideNumber.Size = new Size(70, 13);
            this.lcDecideNumber.TabIndex = 9;
            this.lcDecideNumber.Text = "Số quyết định:";
            this.lcDate.Location = new Point(0xf2, 210);
            this.lcDate.Name = "lcDate";
            this.lcDate.Size = new Size(0x4d, 13);
            this.lcDate.TabIndex = 11;
            this.lcDate.Text = "Ng\x00e0y ban h\x00e0nh:";
            this.lcPerson.Location = new Point(10, 0xee);
            this.lcPerson.Name = "lcPerson";
            this.lcPerson.Size = new Size(80, 13);
            this.lcPerson.TabIndex = 13;
            this.lcPerson.Text = "Người ban h\x00e0nh:";
            this.cboDecideNumber.Location = new Point(0x87, 0xcf);
            this.cboDecideNumber.Name = "cboDecideNumber";
            this.cboDecideNumber.Size = new Size(100, 20);
            this.cboDecideNumber.TabIndex = 10;
            this.cboPerson.Location = new Point(0x87, 0xec);
            this.cboPerson.Name = "cboPerson";
            this.cboPerson.Size = new Size(0x123, 20);
            this.cboPerson.TabIndex = 14;
            this.txtFoundation.Location = new Point(0x87, 0x3f);
            this.txtFoundation.Name = "txtFoundation";
            this.txtFoundation.Size = new Size(0x123, 0x2e);
            this.txtFoundation.TabIndex = 4;
            this.txtReason.Location = new Point(0x87, 0x77);
            this.txtReason.Name = "txtReason";
            this.txtReason.Size = new Size(0x123, 0x24);
            this.txtReason.TabIndex = 6;
            this.txtForm.Location = new Point(0x87, 0xa3);
            this.txtForm.Name = "txtForm";
            this.txtForm.Size = new Size(0x123, 0x22);
            this.txtForm.TabIndex = 8;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.grInformation);
            base.Name = "xucRewardAdd";
            base.Size = new Size(0x1b9, 0x134);
            base.Controls.SetChildIndex(base.btnCancel, 0);
            base.Controls.SetChildIndex(base.btnSave, 0);
            base.Controls.SetChildIndex(base.btnSaveNew, 0);
            base.Controls.SetChildIndex(this.grInformation, 0);
            ((ISupportInitialize) base.Err).EndInit();
            base.imageCollection2.EndInit();
            this.grInformation.EndInit();
            this.grInformation.ResumeLayout(false);
            this.grInformation.PerformLayout();
            this.txtEmployeeName.Properties.EndInit();
            this.glkEmployeeCode.Properties.EndInit();
            this.gridLookUpEdit1View.EndInit();
            this.dtDate.Properties.VistaTimeProperties.EndInit();
            this.dtDate.Properties.EndInit();
            this.cboDecideNumber.Properties.EndInit();
            this.cboPerson.Properties.EndInit();
            this.txtFoundation.Properties.EndInit();
            this.txtReason.Properties.EndInit();
            this.txtForm.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void InitMultiLanguages()
        {
            this.grInformation.Text = MultiLanguages.GetString("tbl_ProcessRewardAdd", "grInformation", this.grInformation.Text);
            this.lcFoundation.Text = MultiLanguages.GetString("tbl_ProcessRewardAdd", "Foundation", this.lcFoundation.Text);
            this.lcReason.Text = MultiLanguages.GetString("tbl_ProcessRewardAdd", "Reason", this.lcReason.Text);
            this.lcForm.Text = MultiLanguages.GetString("tbl_ProcessRewardAdd", "Form", this.lcForm.Text);
            this.lcDate.Text = MultiLanguages.GetString("tbl_ProcessRewardAdd", "Date", this.lcDate.Text);
            this.lcDecideNumber.Text = MultiLanguages.GetString("tbl_ProcessRewardAdd", "DecideNumber", this.lcDecideNumber.Text);
            this.lcPerson.Text = MultiLanguages.GetString("tbl_ProcessRewardAdd", "Person", this.lcPerson.Text);
        }

        private void LoadEmployeeInformation()
        {
            HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
            hrm_employee.Get(this.m_EmployeeCode);
            this.grInformation.Text = "Th\x00f4ng Tin Khen Thưởng - " + hrm_employee.EmployeeCode + " (" + hrm_employee.FirstName + " " + hrm_employee.LastName + ")";
            this.txtEmployeeName.Text = hrm_employee.FirstName + " " + hrm_employee.LastName;
        }

        private void RaiseSuccessEventHander(HRM_PROCESS_REWARD item)
        {
            if (this.Success != null)
            {
                this.Success(this, item);
            }
        }

        public void SetCode(string EmployeeCode)
        {
            this.m_EmployeeCode = EmployeeCode;
            if (this.m_EmployeeCode != "")
            {
                this.glkEmployeeCode.EditValue = this.m_EmployeeCode;
                this.LoadEmployeeInformation();
            }
        }

        public void SetData(HRM_PROCESS_REWARD item)
        {
            this.m_RewardID = item.RewardID;
            SYS_LOG.Insert("Qu\x00e1 Tr\x00ecnh Khen Thưởng", "Xem", this.m_RewardID.ToString());
            this.m_EmployeeCode = item.EmployeeCode;
            this.glkEmployeeCode.EditValue = this.m_EmployeeCode;
            this.glkEmployeeCode.Enabled = false;
            this.txtFoundation.Text = item.Foundation;
            this.txtReason.Text = item.Reason;
            this.txtForm.Text = item.Form;
            this.cboDecideNumber.Text = item.DecideNumber;
            this.dtDate.DateTime = item.Date;
            this.cboPerson.Text = item.Person;
            this.LoadEmployeeInformation();
        }

        protected override string uc_Change()
        {
            return string.Empty;
        }

        protected override string uc_Delete()
        {
            HRM_PROCESS_REWARD item = new HRM_PROCESS_REWARD {
                RewardID = this.m_RewardID
            };
            string str = item.Delete();
            if (str == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            return str;
        }

        protected override string uc_Save()
        {
            if (MyRule.Get(MyLogin.RoleId, "bbiProcessReward") != "OK")
            {
                return "";
            }
            if (!MyRule.AllowAdd)
            {
                MyRule.Notify();
                return "";
            }
            if (this.m_EmployeeCode == "")
            {
                XtraMessageBox.Show("Vui l\x00f2ng chọn nh\x00e2n vi\x00ean để lưu dữ liệu!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK);
                return "";
            }
            SYS_LOG.Insert("Qu\x00e1 Tr\x00ecnh Khen Thưởng", "Th\x00eam", this.m_RewardID.ToString());
            base.SetWaitDialogCaption("Đang lưu dữ liệu...");
            Cursor.Current = Cursors.WaitCursor;
            HRM_PROCESS_REWARD item = new HRM_PROCESS_REWARD {
                RewardID = Guid.NewGuid(),
                EmployeeCode = this.m_EmployeeCode,
                Foundation = this.txtFoundation.Text,
                Reason = this.txtReason.Text,
                Form = this.txtForm.Text,
                Date = this.dtDate.DateTime,
                DecideNumber = this.cboDecideNumber.Text,
                Person = this.cboPerson.Text
            };
            string text = item.Insert();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            Cursor.Current = Cursors.Default;
            this.DoHide();
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return text;
        }

        protected override string uc_Update()
        {
            if (MyRule.Get(MyLogin.RoleId, "bbiProcessReward") != "OK")
            {
                return "";
            }
            if (!MyRule.AllowEdit)
            {
                MyRule.Notify();
                return "";
            }
            SYS_LOG.Insert("Qu\x00e1 Tr\x00ecnh Khen Thưởng", "Cập Nhật", this.m_RewardID.ToString());
            base.SetWaitDialogCaption("Đang cập nhật dữ liệu...");
            HRM_PROCESS_REWARD item = new HRM_PROCESS_REWARD {
                RewardID = this.m_RewardID,
                EmployeeCode = this.m_EmployeeCode,
                Foundation = this.txtFoundation.Text,
                Reason = this.txtReason.Text,
                Form = this.txtForm.Text,
                Date = this.dtDate.DateTime,
                DecideNumber = this.cboDecideNumber.Text,
                Person = this.cboPerson.Text
            };
            string text = item.Update();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            this.DoHide();
            return text;
        }

        public delegate void SuccessEventHander(object sender, HRM_PROCESS_REWARD item);
    }
}

